home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Re: A real basic problem?: (code!) long integers or compiler problem?
- Date: 19 Apr 1996 03:15:19 GMT
- Organization: University of Guelph
- Message-ID: <4l70g7$m7i@ccshst05.uoguelph.ca>
- References: <4l3mom$f26@newsbf02.news.aol.com> <4l699u$cgo@newsbf02.news.aol.com>
- NNTP-Posting-Host: ccshst01.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- The Oder (theoder@aol.com) wrote:
- : I'm in the process of relearning C and have been doing some beginning
- : programs on my PC. I have two compilers (Borland C++ and Power C). My
- : problem is that when I run a program using "long" integers (i.e. declare a
- : variable as "long"), it locks up immediately and I have to reboot. This
- : has happened with both compilers and with two different really basic
- : programs (i.e. just trying to do a loop that will compute the first 10
- : powers of 2, and another one that simply just tries to find the largest
- : positive long value on my computer--> I can find the largest positive int
- : value, but when I convert it to long, it locks up)
- code snipped - see original post.
-
- It appears to me that the program finds the largest positive integer by
- assigning 10000 to an int variable and then incrementing the variable
- until it goes from positive to negative. In Turbo C, with MAXINT at
- about 32767, that's 20000+ iterations - this should complete in a matter
- of seconds. Using a long variable instead of an int should cause the
- program to run longer because it will count instead to about 2147483647.
- This will take about 30000 times as long (someone correct me if I'm
- wrong). My guess is that your computer hasn't locked up - it's just busy
- counting and you can't get its attention. If you wait longer (a day or
- two) it will give you the correct answer.
- Toby Hay thay@uoguelph.ca
-